﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cronos.DateTimeExtensions
{
    public static class DateExtensions
    {
        public static DateTime Tomorrow(this object source)
        {
            return DateTime.Now.AddDays(1);
        }

        public static bool IsWeekend(this DateTime source)
        {
            return source.DayOfWeek == DayOfWeek.Saturday || source.DayOfWeek == DayOfWeek.Sunday;
        }

        public static DateTime Yesterday(this object source)
        {
            return DateTime.Now.AddDays(-1);
        }

        public static bool Is(this DateTime from, DateTime to)
        {
            return from.Date == to.Date;
        }

        public static DateTime BeginningOfDay(this DateTime source)
        {
            return source.Date;
        }

        public static DateTime EndingOfDay(this DateTime source)
        {
            return source.Date.Add(new TimeSpan(23, 59, 59));
        }

        public static DateTime Next(this object source, DayOfWeek nextDayOfWeek)
        {
            var currentDate = DateTime.Today;
            do
            {
                currentDate = currentDate.AddDays(1);
            }
            while(currentDate.DayOfWeek != nextDayOfWeek);

            return currentDate;
        }

        public static DateTime Last(this object source, DayOfWeek lastDayOfWeek)
        {
            var currentDate = DateTime.Today;
            do
            {
                currentDate = currentDate.AddDays(-1);
            }
            while (currentDate.DayOfWeek != lastDayOfWeek);

            return currentDate;
        }
    }
}
